package com.baizhi.service.impl;

import com.baizhi.dao.DrugDao;
import com.baizhi.entity.Drug;
import com.baizhi.service.DrugService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DrugServiceImpl implements DrugService {
    @Autowired
    private DrugDao drugDao;
    @Override
    public void insertDrug(Drug drug) {
        drugDao.insertDrug(drug);
    }

    @Override
    public void deleteDrug(Integer drugid) {
        drugDao.deleteDrug(drugid);
    }

    @Override
    @Transactional(readOnly = true)
    public Drug selectById(Integer drugid) {
        return drugDao.selectById(drugid);
    }

    @Override
    public void updateDrug(Drug drug) {
        drugDao.updateDrug(drug);
    }

    @Override
    @Transactional(readOnly = true)
    public PageInfo<Drug> selectDrugs(String name, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Drug> drugs = drugDao.selectDrugs(name);
        PageInfo<Drug> pageInfo = new PageInfo<>(drugs);
        return pageInfo;
    }
}
